package cn.itcast.controller;

import cn.itcast.domain.Standard;
import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName StandardController
 * @Descrintion TODO
 * @Author wly
 * @Date 2019/1/20 15:38
 * @Version 1.0
 **/
@Controller
public class StandardController {

    @Autowired
    private StandardService standardService;

    @RequestMapping("/standard_pageQuery")
    @ResponseBody
    public Map pageQuery(int page , int rows){
        PageRequest pageRequest = PageRequest.of(page - 1, rows);
        Page<Standard> pageResult = standardService.findAll(pageRequest);
        Map  map = new HashMap();
        map.put("total" , pageResult.getTotalElements());
        map.put("rows" , pageResult.getContent());
        return map;
    }

    @RequestMapping("/standard_save")
    public String save(Standard standard){
        standardService.save(standard);
        return "redirect:/pages/base/standard.html";
    }
}
